package com.itcs.box.util;

import com.itcs.box.domain.BoxData;
import com.itcs.box.domain.BoxResponse;

/**
 * 通讯盒返回工具类
 * 
 * @author LiuPeng
 * @date 2018年1月31日
 * 
 */
public class BoxResUtils {

	/**
	 * 心跳测试请求组装
	 * 
	 * @param deviceId
	 * @return
	 */
	public static BoxResponse build1002(String deviceId) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("1002");

		BoxData boxData = new BoxData();
		boxData.setDeviceId(deviceId);
		boxData.setStatus("1");
		boxResponse.setData(boxData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/**
	 * 心跳回复
	 * 
	 * @param data
	 * @return
	 */
	public static BoxResponse build2002(BoxData data) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2002");

		BoxData boxData = new BoxData();
		boxData.setDeviceId(data.getDeviceId());
		boxData.setStatus("1");
		boxResponse.setData(boxData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/** 
	 * 出口车辆白名单主动下发
	 * @param deviceId
	 * @param plateNum 车牌数量 
	 * @param iCarPlate 车牌号车型（多车牌以小数点隔开）
	 * @param iPlateColor 车牌颜色
	 * @param iCarClass 车牌类型
	 * @return 
	 */
	public static BoxResponse build2005(String deviceId, String plateNum, String iCarPlate, String iPlateColor,
			String iCarClass) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2005");

		BoxData responseData = new BoxData();
		String nowTime = DateUtils.getUnixTimeStamp();

		responseData.setDeviceId(deviceId);
		responseData.setPlateNum(plateNum);
		responseData.setiCarPlate(iCarPlate);
		responseData.setiPlateColor(iPlateColor);
		responseData.setiCarClass(iCarClass);
		responseData.setiTollStationCode("");
		responseData.setiLaneNo("");
		responseData.setiTime(nowTime);
		// 是否领卡 1:虚拟卡 2:通行卡
		responseData.setIsCard("2");
		responseData.setRequestTime(nowTime);
		boxResponse.setData(responseData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/**
	 * 2015支付请求应答
	 * 
	 * @param boxRequestData
	 * @return
	 */
	public static BoxResponse build2015(BoxData boxRequestData) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2015");

		BoxData responseData = new BoxData();

		responseData.setDeviceId(boxRequestData.getDeviceId());
		responseData.setTransacSeq(boxRequestData.getTransacSeq());
		responseData.setResult("1");
		responseData.setReplyTime(DateUtils.getUnixTimeStamp());
		boxResponse.setData(responseData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/**
	 * 2007支付请求应答
	 * 
	 * @param boxRequestData
	 * @return
	 */
	public static BoxResponse build2007(BoxData boxRequestData) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2007");

		BoxData responseData = new BoxData();

		responseData.setDeviceId(boxRequestData.getDeviceId());
		responseData.setTransacSeq(boxRequestData.getTransacSeq());
		responseData.setResult("1");
		responseData.setReplyTime(DateUtils.getUnixTimeStamp());
		boxResponse.setData(responseData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/**
	 * 2008支付成功通知
	 * 
	 * @param boxRequestData
	 * @param payResult
	 *            支付结果：1:成功；2：欠费；9:其他
	 * @param payType
	 *            支付类型
	 * @param payChannelCode
	 *            第三方支付平台代码
	 * @param invoice
	 *            是否打印发票:1:是 2:否
	 * @return
	 */
	public static BoxResponse build2008(BoxData boxRequestData, String payResult, String payType, String payChannelCode,
			String invoice) {
		return build2008(boxRequestData.getDeviceId(), boxRequestData.getTransacSeq(), payResult, payType,
				payChannelCode, invoice);
	}

	/**
	 * 2008支付成功通知
	 * 
	 * @param deviceId
	 *            通讯盒ID
	 * @param transacSeq
	 *            车道流水号
	 * @param payResult
	 *            支付结果：1:成功；2：欠费；9:其他
	 * @param payType
	 *            boxRequestData
	 * @param payChannelCode
	 *            第三方支付平台代码
	 * @param invoice
	 *            是否打印发票:1:是 2:否
	 * @return
	 */
	public static BoxResponse build2008(String deviceId, String transacSeq, String payResult, String payType,
			String payChannelCode, String invoice) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2008");

		BoxData responseData = new BoxData();

		responseData.setDeviceId(deviceId);
		responseData.setTransacSeq(transacSeq);
		responseData.setPayResult(payResult);
		responseData.setPayType(payType);
		responseData.setPayChannelCode(payChannelCode);
		// 暂定为1
		responseData.setInvoice("1");
		responseData.setReplyTime(DateUtils.getUnixTimeStamp());
		boxResponse.setData(responseData);

		boxResponse.setKey("1");
		return boxResponse;
	}

	/**
	 * 2009车道交易完成结果应答
	 * 
	 * @param boxRequestData
	 * @return
	 */
	public static BoxResponse build2009(BoxData boxRequestData, String result) {
		BoxResponse boxResponse = new BoxResponse();
		boxResponse.setMessgeType("2009");

		BoxData responseData = new BoxData();

		responseData.setDeviceId(boxRequestData.getDeviceId());
		responseData.setTransacSeq(boxRequestData.getTransacSeq());
		responseData.setResult(result);
		responseData.setReplyTime(DateUtils.getUnixTimeStamp());
		boxResponse.setData(responseData);

		boxResponse.setKey("1");
		return boxResponse;
	}

}
